<template>
	<view   class="content yingyeclass">
			<view class="grace-idcard-items">
				<view class="grace-idcard-uper-btn relative" >
					<view class="img" v-if="requestcerinfo.src" @tap="selectImg1">
						<image style="height:300upx !important;" :src="requestcerinfo.src" mode="widthFix" />
					</view>
					<!-- <uni-icons type="plus-filled" color='#06C' size="50"></uni-icons>
					<view class="text">请上传营业执照副本正面</view> -->
					<view class="noimginshow" v-if="!requestcerinfo.src"  @tap="selectImg1">
						<view class="img"><img style="height:300upx !important;" :src="yingye_yb" mode="widthFix" /></view>
						<view class="textdiv">
							<uni-icons type="plus-filled" color='#06C' size="50"></uni-icons>
							<view class="text">请上传营业执照副本正面</view>
						</view>
					</view>
					<view class="deltrash" v-if="requestcerinfo.src" @tap="delimgsrc('selectImg1')">
						<uni-icons type="trash" color='#06C' size="30"></uni-icons>
					</view>
				</view>
			</view>
			
			<view class="grace-idcard-items">
				<view class="grace-idcard-uper-btn relative" >
					<view class="img" v-if='warrantsrc' @tap="selectImg2">
						<image style="height:300upx !important;" :src="warrantsrc" mode="widthFix" />
					</view>
					<!-- <uni-icons type="plus-filled" color='#06C' size="50"></uni-icons>
					<view class="text">请上传授权书</view> -->
					
					<view class="noimginshow" v-if="!warrantsrc"  @tap="selectImg2">
						<view class="img">
							<img style="height:300upx !important;" :src="shouquanshu_yb" mode="widthFix" /></view>
						<view class="textdiv">
							<uni-icons type="plus-filled" color='#06C' size="50"></uni-icons>
							<view class="text">请上传授权书</view>
						</view>
					</view>
					<view class="deltrash" v-if="warrantsrc" @tap="delimgsrc('warrantsrc')">
						<uni-icons type="trash" color='#06C' size="30"></uni-icons>
					</view>				
					
				</view>
				
			</view>
			<view class="f14 p5">
				<text style="text-align: center; margin:auto;">请加客服微信：18938746486；索取授权书模版文档</text>
			</view>
		<view class="input-group">


			<view class="input-row border">
				<text class="title">企业法人：</text>
				<!-- <div class="cvc">{{cerbusinessInfo.corporation}}</div> -->
				<m-input v-if="requestcerinfo.src" type="text" clearable v-model="cerbusinessInfo.corporation" placeholder=""></m-input>
			</view>



			<view class="input-row border">
				<text class="title">信用代码：</text>
				<!-- <div class="cvc">{{cerbusinessInfo.code}}</div> -->
				<m-input v-if="requestcerinfo.src" type="text" clearable v-model="cerbusinessInfo.code" placeholder=""></m-input>
			</view>

			<view class="input-row border">
				<text class="title">企业名称：</text>
				<!-- <div class="cvc">{{cerbusinessInfo.name}}</div> -->
				<m-input v-if="requestcerinfo.src" type="text" clearable v-model="cerbusinessInfo.name" placeholder=""></m-input>
			</view>

			<view class="input-row border">
				<text class="title">企业地址：</text>
				<!-- <div class="cvc">{{cerbusinessInfo.address}}</div> -->
				<m-input v-if="requestcerinfo.src" type="text" clearable v-model="cerbusinessInfo.address" placeholder=""></m-input>
			</view>
			
			<view class="input-row border">
		        <text class="title">手机号码：</text>
				<m-input type="text" clearable v-model="mobile" placeholder="请输入手机号码"></m-input>
				
		    </view>
			<!-- <view class="input-row">
		        <text class="title">邮箱：</text>
		        <m-input type="text" clearable v-model="email" placeholder="请输入邮箱"></m-input>
		    </view> -->
		</view>
		<view class=" uni-row w90 mauto pT30 uni-flex">
		<!-- <view class=" uni-row w90 mauto pT30" :class="showtype==''?'uni-flex':''"> -->
			<!-- <view :class="showtype==''?'btn-row':'btn-row btn-row3'" >
				<button type="primary" class="primary " @tap="register">提交</button>
			</view> -->
			<view class="btn-row" >
				<button type="primary" class="primary " @tap="register">提交</button>
			</view>
			<!-- <view class="btn-row" v-if="!showtype">
				<button type="warn" @tap="registerxx">返回首页</button>
			</view> -->
			<view class="btn-row">
				<button type="warn" @tap="registerxx">返回首页</button>
			</view>
		</view>

	<backnext></backnext>
	</view>
</template>
<script>
	var _self;
	import mInput from '../../components/m-input.vue';
	import graceChecker from '../../common/graceChecker.js'
	import md5 from '../../common/md5.js'
	import {
		isEmpty
	} from '@/common/graceChecker.js'
	import request from '../../common/vmeitime-http/requstx.js'
	
	import {licenseupload,companyedit} from '@/common/api/company.js'
	import {companyinfo} from '../../common/api/user.js'; //引进requst方法
	import {userinfo} from '../../common/api/user.js';
	
	export default {
		components: {
			mInput
		},
		data() {
			return {
				yingye_yb:this.$_GENV.Gdoamin_https + '/static/theme/img/yb.png',
				shouquanshu_yb:this.$_GENV.Gdoamin_https + '/static/theme/img/sqs.png',
				cerbusinessInfo:{
					address:'',
					code:'',
					corporation:'',
					name:'',
					src:''
				},
				warrantsrc:'',
				account: '',
				password: '',
				mobile:"",
				repassword: '',
				email: '',
				captchaImg: '',
				message_code: '',
				seconds: 60,
				clickstate:true,
				codeBtn: {
					text: '获取验证码',
					waitingCode: false,
					count: this.seconds
				},
				idCard1: '',
				idCard2: '',
				code: '',
				shenfenx: '',
				
				xingbie: '',
				fading: '',
				dizhi: '',
				requestcerinfo:{
					src:"",
				},
				showtype:'',
				
			};
		},
		onLoad: function(event) {
			_self = this;
			if(event.type){
				this.showtype=event.type;
				companyinfo({id:event.companyid,type:'CH'}).then(res=>{
					console.log(res)
					if(res.data.data){
						this.cerbusinessInfo.address=res.data.data.address;
						this.cerbusinessInfo.code=res.data.data.code;					
						this.cerbusinessInfo.corporation=res.data.data.corporation;
						this.cerbusinessInfo.name=res.data.data.name;
						this.requestcerinfo.src=res.data.data.imgurl;
						this.mobile=res.data.data.company_mobile;
						this.warrantsrc=res.data.data.warrant;
					}
				
					
				})
			}
		},
		onShow:function(evemt){
			userinfo({}).then(res=>{//获取用户信息
			console.log(res)
			/* 400 */
			if(res.data.code==400){
				uni.showModal({
					title: '提示',
					showCancel:false,
					content: res.data.message,
					success: function (clickres) {
					    if (clickres.confirm) {
							uni.reLaunch({
							    url: '/pages/shouquan/shouji'
							});
					    }
					}
				});
			}
			if(res.data.data.is_completeperson!=2){
			    uni.reLaunch({
			        url: '/pages/user/user'
			    });
			   }
			// if(res.data.data.is_completeperson!=2){
			// 	uni.reLaunch({
			// 	    url: '/pages/shouquan/yingye'
			// 	});
			// }
			
			uni.setStorage({
			    key: 'userinfo',
			    data: res.data.data,
			    success: function () {
			        console.log('success');
			    },
				fail:function(){
					console.log('faild')
				}
			});
			
			});
		},
		methods: {
			delimgsrc(type){
				if(type=='warrantsrc'){
					this.warrantsrc='';
				}else{
					this.requestcerinfo.src='';					
					this.cerbusinessInfo.address="";
					this.cerbusinessInfo.code="";
					this.cerbusinessInfo.corporation="";
					this.cerbusinessInfo.name="";
					
				}
			},
			selectImg2(){
				licenseupload({
					type:'warrant'
				}).then(res=>{
					console.log(res)
					if(res.statusCode == 200 ){
						var tmpcerinfo =JSON.parse(res.data) 
					
						if(tmpcerinfo.code == 200){
								this.warrantsrc = tmpcerinfo.src
						}else{
							uni.showToast({
							    icon: 'none',
							    title: tmpcerinfo.message
							});
						}
						
					}
				
				})
			},
			selectImg1(){
				licenseupload({
					
				}).then(res=>{
					console.log(res)
					if(res.statusCode == 200 ){
						var tmpcerinfo =JSON.parse(res.data) 
						this.requestcerinfo = tmpcerinfo
						if(tmpcerinfo.code == 200){
							this.cerbusinessInfo = tmpcerinfo.data
						}else{
							uni.showToast({
							    icon: 'none',
							    title: tmpcerinfo.message
							});
						}
					}
				
				})

			},



			// previewImg1 : function(){
			// 	uni.previewImage({
			// 		urls:[_self.idCard1]
			// 	});
			// },
			register: function() {
				let that=this;
				/**
				 * 客户端对账号信息进行一些必要的校验。
				 * 实际开发中，根据业务需要进行处理，这里仅做示例。
				 */
				
				if(!this.requestcerinfo.src){
					uni.showToast({
					    icon: 'none',
					    title: '请上传营业执照副本正面'
					});
					return;
				}
				if(!this.cerbusinessInfo.corporation){
					uni.showToast({
					    icon: 'none',
					    title: '请修改正确的企业法人'
					});
					return;
				}
				if(!this.cerbusinessInfo.code){
					uni.showToast({
					    icon: 'none',
					    title: '请修改正确的信用代码'
					});
					return;
				}
				if(!this.cerbusinessInfo.name){
					uni.showToast({
					    icon: 'none',
					    title: '请修改正确的企业名称'
					});
					return;
				}
				
				if(!this.cerbusinessInfo.address){
					uni.showToast({
					    icon: 'none',
					    title: '请修改正确的企业地址'
					});
					return;
				}
				if(!this.warrantsrc){
					uni.showToast({
					    icon: 'none',
					    title: '请上传授权书'
					});
					return;
				}
				
				if(!this.mobile){
					uni.showToast({
					    icon: 'none',
					    title: '请输入企业电话'
					});
					return;
				}
				if(this.mobile.length!=11){
					uni.showToast({
					    icon: 'none',
					    title: '请输入正确的手机号码'
					});
					return;
				}
				if(this.clickstate){
					this.clickstate=false;
					setTimeout(()=>{
						this.clickstate=true;
					},2000)
					uni.showModal({
					    title: '确定要提交资料认证?',
					    success: function (res) {
					        if (res.confirm) {
								companyedit({
									name:that.cerbusinessInfo.name,
									code:that.cerbusinessInfo.code,
									imgurl:that.requestcerinfo.src,
									corporation:that.cerbusinessInfo.corporation,
									address:that.cerbusinessInfo.address,
									mobile:that.mobile,
									warrant:that.warrantsrc,
								}).then(res=>{
									if(res.data.code == 200){
										// uni.showToast({
										//     icon: 'none',
										//     title: '提交成功，请耐心的等待管理员审核'
										// });
										// setTimeout(()=>{
										// 	uni.reLaunch({
										// 		url: '/pages/user/user'
										// 	});
										// },1000)
										uni.showModal({
											title: '',
											content: '资料上传成功\r\n请等待审核！',	
											showCancel:false,
											buttonText: '确定',
											confirmText: "确定",
											success: function (res) {
												if (res.confirm) {
													uni.reLaunch({
														url: '/pages/user/user'
													});
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
									}else{
										uni.showToast({
										    icon: 'none',
										    title: res.data.message
										});
									}
								})
								
								
								
								
					            // console.log('用户点击确定');
					        } else if (res.cancel) {
								/*bann*/
								return 
					            // console.log('用户点击取消');
					        }
					    }
					});
					
				
				}
				return ;




			},

			registerxx: function() {
				uni.reLaunch({
					url: '/pages/user/user'
				});
			},
			sendCode: function() {
				this.codeBtn.waitingCode = true;
				this.codeBtn.count = this.seconds;
				this.codeBtn.text = this.codeBtn.count + 's';

				let countdown = setInterval(() => {
					this.codeBtn.count--;
					this.codeBtn.text = this.codeBtn.count + 's';
					if (this.codeBtn.count < 0) {
						clearInterval(countdown);
						this.codeBtn.text = '重新发送';
						this.codeBtn.waitingCode = false;
					}
				}, 1000);

				console.log(221)
				const data = {
					username: this.captchaImg,

				}
				request({
					url: "user/send",
					method: 'POST',
					data: {
						mobile: this.captchaImg
					},
					success: function(res) {
						console.log(res.data);
					}
				})

			},
			gotoLogin: function() {
				uni.navigateTo({
					url: 'login'
				})
			}

		},
		computed: {
			disableCodeBtn: function() {
				return this.codeBtn.waitingCode || this.captchaImg.length < 11;
			}
		}
	}
</script>
<style>
	.yingyeclass .input-group{margin-top: 0;}
	.cvc {
		line-height: 40px;
	}
.content {
			display: flex;
			flex: 1;
			flex-direction: column;
			background-color: #efeff4;
		}
	.sb {
		font-size: 15px;
		width: 104px;
		margin-right: 10px;
		margin-top: 5px;
		margin-bottom: 5px;
	}

	img {
		height: 300upx !important;
	}

	view {
		font-size: 28upx;
	}

	.grace-idcard-main {
		margin: 20upx 30upx;
	}

	.grace-idcard-desc {
		line-height: 2em;
		background: #FFFFFF;
		padding: 20upx;
		border-radius: 10upx;
	}

	.grace-idcard-text {
		line-height: 2em;
		margin-top: 30upx;
	}

	.grace-idcard-items {
		background: #FFFFFF;
		padding: 10upx 0;
		display: flex;
		/* margin: 20upx 0; */
		border-radius: 10upx;
		align-items: flex-start;
	}

	.grace-idcard-uper-btn {
		width: 576upx;
		height: 350upx;
		margin: 0 auto;
		background: #F1F1F1;
		padding-bottom: 10upx;
		border-radius: 10upx;
		text-align: center;
	}

	.grace-idcard-uper-btn .img {
		width: 500upx;
		height: 100upx;
		margin: 0 auto;
		margin-top: 30upx;
	}

	.grace-idcard-uper-btn .img image {
		width: 500upx;
		height: 300upx !important;
	}

	.grace-idcard-uper-btn .text {
		width: 100%;
		margin-top: 10upx;
		text-align: center;
		line-height: 2em;
	}

	.grace-idcard-preview {
		width: 50%;
		margin: 0 30upx;
	}

	.grace-idcard-preview image {
		width: 100%;
		height: 300upx !important;
	}
	.yingyeclass .btn-row{width: 35%;margin: 0 auto;}
	.yingyeclass .btn-row3{width: 50%;margin: 0 auto;}
	.yingyeclass .btn-row .primary{background-color: #007aff;}
	
	.noimginshow .img{opacity: 0.5;}
	.noimginshow .text{color: #06C;}
	.noimginshow .textdiv{    position: absolute; width: 100%; text-align: center; left: 0;}
	.deltrash{position: absolute; text-align: center; right: 10upx;top:10upx;background-color: #fff;}
</style>
